/* Copyright © 2010 LPRM
Universidade Federal do Espírito Santo - RNP-GT CWTools

This file is part of JoinUs!.

JoinUs! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

JoinUs! is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JoinUs!. If not, see <http://www.gnu.org/licenses/>. */
package br.ufes.inf.joinus;

import java.io.IOException;
import java.util.Set;
import java.util.Map.Entry;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetPost extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response){
		doGet(request, response);
	}
	
	@SuppressWarnings("unchecked")
	protected void doGet(HttpServletRequest request, HttpServletResponse response){
		Set<Entry<String, String[]>> params = request.getParameterMap().entrySet();
		
		for(Entry<String, String[]> param: params){
			String[] sl = param.getValue();
			StringBuilder sb = new StringBuilder();
			for(String val: sl){
				sb.append(val + ", ");
			}
			String vals = sb.toString();
			vals = vals.substring(0, vals.length()-2);
			try {
				response.getOutputStream().println(param.getKey() + ": " + vals);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
